package demo.DataStrucAndAlgo.SingletonPattern;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/7/30-07-30-9:28
 * @Description：demo.DataStrucAndAlgo.SingletonPattern   登记式/静态内部类
 */
/*
登记式/静态内部类
    懒初始化
    多线程安全
 */
public class SingletonInnerClass {
    private static class SingletonHoder{
        private static SingletonInnerClass INSTANCE
                = new SingletonInnerClass();
    }
    private SingletonInnerClass(){}

    public static SingletonInnerClass getInstance(){
        return SingletonHoder.INSTANCE;
    }

    public static void main(String[] args) {
        SingletonInnerClass Single = SingletonInnerClass.getInstance();
        SingletonInnerClass Single2 = SingletonInnerClass.getInstance();
        System.out.println(Single == Single2);
    }
}
